<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 准备一个容器 -->
    <div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom，支持react操作dom -->
    <script src="../js/react-dom.development.js"></script>
    <!-- 引入babel，将jsx转为js -->
    <script src="../js/babel.min.js"></script>
    <!-- 引入prop-types ，对标签属性进行限制 -->
    <script src="../js/prop-types.js"></script>

    <script type="text/babel">/*此处写babel*/ 

        /*
        //1.创建虚拟DOM
        class Person extends React.Component{
            //对标签属性进行类型、必要性的限制
            //用static直接在类里面写静态属性
            static propTypes = {
                name:PropTypes.string.isRequired,//限制name必传，且为字符串
                age:PropTypes.number,   //限制age为数值
                sex:PropTypes.string,
                speak:PropTypes.func    //限制为函数
            }
            //指定标签的默认属性值
            static defaultProps = {
                sex:'男',
                age:18
            }
            render(){
                const{name,age,sex} = this.props;//
                return(
                    <ul>
                        <li>姓名: {name}</li>
                        <li>性别: {sex}</li>
                        <li>年龄: {age+1}</li>
                    </ul>
                )
            }
        }*/
//函数组件只能用用props，state和refs都不能用
        function Person(props) {
            const {name,age,sex} = props;
            return(
                    <ul>
                        <li>姓名: {name}</li>
                        <li>性别: {sex}</li>
                        <li>年龄: {age+1}</li>
                    </ul>
                )
        }
        //限制只能写到外面咯
        Person.propTypes = {
            name:PropTypes.string.isRequired,//限制name必传，且为字符串
            age:PropTypes.number,   //限制age为数值
            sex:PropTypes.string,
            speak:PropTypes.func    //限制为函数
        }
        Person.defaultProps = {
            sex:'男',
            age:18
        }
        //2.渲染虚拟DOM到页面
        ReactDOM.render(<Person name={100}/>,document.getElementById('test2'));
    </script>
</body>
</html>